//
//  VmixMobileDemoAppDelegate.m
//  VmixMobileDemo
//
//  Created by jeffs on 6/15/10.
//  Copyright VMIX Media 2010. All rights reserved.
//

#import "VmixMobileDemoAppDelegate.h"
#import "RootViewController.h"
#import <CFNetwork/CFNetwork.h>


@implementation VmixMobileDemoAppDelegate

@synthesize window;
@synthesize tabBarController;


#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    // Override point for customization after app launch    
	
	//Test for connection to vmix api before launching the applicaiton.
	NSString *vmixAPI = [NSString stringWithFormat:@"http://api.vmixcore.com"];
	NSURL *url = [NSURL URLWithString: vmixAPI];
	NSURLRequest *request=[NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:15.0];
	NSURLConnection *initialConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self];
	[initialConnection release];
	
	[window addSubview:[tabBarController view]];
    [window makeKeyAndVisible];

	return YES;
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    //
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    //
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
	
	if ([error code] == kCFURLErrorNotConnectedToInternet)
	{
		
		NSString *title = [NSString stringWithFormat:@"Network Connection Required"];
		NSString *alertMessage = @"This application requires an internet connection to function properly. Please connect to the internet and re-launch the application";
		NSString *ok = [NSString stringWithFormat:@"Ok"];
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:alertMessage  delegate:self cancelButtonTitle:ok otherButtonTitles:nil];
		[alert show];
		[alert release];
		
		
	}
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{

	
}




- (void)applicationWillTerminate:(UIApplication *)application {
	// Save data if appropriate
}


#pragma mark -
#pragma mark Memory management

- (void)dealloc {
	[tabBarController release];
	[window release];
	[super dealloc];
}


@end

